package com.storm.lib.util;

import java.util.ArrayList;
import java.util.List;


import org.apache.mina.core.session.IoSession;

import com.storm.lib.type.SessionType;
import com.storm.lib.type.ThreadLocalType;
import com.storm.lib.vo.MsgVo;

/**
 * 
 * 类功能:Session工具类
 * @author johnny
 * @version 2011-8-29
 */
public class BaseSessionUtil {

	/**
	 * 方法功能:得到当前session Role
	 * 更新时间:2011-8-29, 作者:johnny
	 * @return
	 */
	public static Object getCurrentSessionRole() {
		IoSession session =(IoSession) ThreadLocalUtil.getVar(ThreadLocalType.CURRENT_SESSION);
		Object obj = (Object) session.getAttribute("rolePo");
		return obj;
	}

	/**
	 * 
	 * 方法功能:增加到当前请求的返回值
	 * 更新时间:2011-8-30, 作者:johnny
	 * @param rolePo
	 */
	public static void addDataArray(Object obj) {
		Object data = ThreadLocalUtil.getVar(SessionType.RESPONSE_VO_DATAS);
		if(data==null){
			ThreadLocalUtil.putVar(SessionType.RESPONSE_VO_DATAS,new ArrayList<Object>());
		}
		List<Object> responseDatas = (List<Object>) ThreadLocalUtil.getVar(SessionType.RESPONSE_VO_DATAS);
		responseDatas.add(obj);
		ThreadLocalUtil.putVar(SessionType.RESPONSE_VO_DATAS, responseDatas);
	}
	
	
	public static IoSession getCurrentSession() {
		IoSession ioSession = (IoSession) ThreadLocalUtil.getVar(ThreadLocalType.CURRENT_SESSION);
		return ioSession;
	}

	
	public static void addConfirmMessageVo(String string) {
		MsgVo messageVo=MsgVo.newConfirm(string);
		Object data = ThreadLocalUtil.getVar(SessionType.RESPONSE_VO_MESSAGE);
		if(data==null){
			ThreadLocalUtil.putVar(SessionType.RESPONSE_VO_MESSAGE,new ArrayList<MsgVo>());
		}
		List<MsgVo> responseMessages = (List<MsgVo>) ThreadLocalUtil.getVar(SessionType.RESPONSE_VO_MESSAGE);
		responseMessages.add(messageVo);
		ThreadLocalUtil.putVar(SessionType.RESPONSE_VO_MESSAGE, responseMessages);
	}

}
